//
//  TTotheMatchUserView.m
//  TaTogether
//
//  Created by 九月 on 10/11/24.
//

#import "TTotheMatchUserView.h"

@interface TTotheMatchUserView ()

@property (assign, nonatomic) BOOL ttotheIsVideo;

@property (nonatomic, copy) void (^ttotheActionBlock)(NSString *ttotheKey);

@end

@implementation TTotheMatchUserView

+ (instancetype)ttotheMatchUserViewActionWith:(UIView *)ttotheView block:(void (^)(NSString *ttothe))ttotheBlock
{
    TTotheMatchUserView *ttothe = [[TTotheMatchUserView alloc]init];
//    [[YUBKeepAppToolClass getWindow] addSubview:alertView];
    ttothe.ttotheActionBlock = ttotheBlock;
    [ttothe ttotheSetupUI];
    
    return ttothe;
}

- (instancetype)init
{
    if (self = [super init]) {

        self.size = CGSizeMake(311,431);
        self.backgroundColor = [UIColor clearColor];
        self.layer.cornerRadius = 12;
        self.layer.masksToBounds = YES;
        
    }
    return self;
}

- (void)ttotheOnUserDetail {
}

- (void)ttotheSetupUI {
    UIButton *cancelBtn = ({
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setTitle:@"匹配下一个" forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:16];
        button.layer.cornerRadius = 25;
        button.layer.masksToBounds = YES;
        button.layer.borderColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1].CGColor;
        button.layer.borderWidth = 1;
        [button setTitleColor:[UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1] forState:UIControlStateNormal];
        button;
    });
    cancelBtn.frame = CGRectMake(0, self.height-50, (self.width-19)*0.5, 50);
    [self addSubview:cancelBtn];
    self.nextBtn = cancelBtn;
    
    UIButton *deleteBtn = ({
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setTitle:self.ttotheIsVideo ? @"开始视频通话":@"开始语音通话" forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:14];
        button.layer.cornerRadius = 25;
        button.layer.masksToBounds = YES;
        [button setTitleColor:[UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1] forState:UIControlStateNormal];
        button;
    });
//        UIImage *bg = [UIImage gradientColorImageFromColors:@[UIColorHex(0xFF97AA), UIColorHex(0xFF3564)] gradientType:GradientTypeTopToBottom imgSize:CGSizeMake(cancelBtn.width, 50)];
    deleteBtn.frame = CGRectMake(cancelBtn.right+19, cancelBtn.top, cancelBtn.width, cancelBtn.height);
    [self addSubview:deleteBtn];
    self.callBtn = deleteBtn;
    
    self.coverView = ({
        UIImageView *view = [[UIImageView alloc] init];
        view.contentMode = UIViewContentModeScaleAspectFill;
        view.clipsToBounds = YES;
        view.layer.cornerRadius = 12;
        view.layer.masksToBounds = YES;
        view.userInteractionEnabled = YES;
        view;
    });
    [self.coverView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(ttotheOnUserDetail)]];
    self.coverView.frame = CGRectMake(0, 0, self.width, self.height-70);
    [self addSubview:self.coverView];
    
    self.infoLabel = [[UILabel alloc] init];
    self.infoLabel.textColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1];
    self.infoLabel.font = [UIFont systemFontOfSize:12];
    [self addSubview:self.infoLabel];
    [self.infoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(17);
        make.leading.equalTo(@12);
        make.bottom.equalTo(self.coverView).offset(-12);
    }];
    
    self.nameLabel = [[UILabel alloc] init];
    self.nameLabel.textColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1];
    self.nameLabel.font = [UIFont systemFontOfSize:18 weight:UIFontWeightMedium];
    [self addSubview:self.nameLabel];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(25);
        make.bottom.mas_equalTo(self.infoLabel.mas_top).offset(-6);
        make.leading.equalTo(self.infoLabel);
    }];
    
    UIView *iview = [[UIView alloc] init];
    iview.layer.cornerRadius = 12;
    iview.layer.masksToBounds = YES;
    iview.backgroundColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.5];
    [self addSubview:iview];
    [iview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(24);
        make.leading.top.equalTo(@12);
    }];
    

    
    UIButton *hiddenBtn = ({
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.showsTouchWhenHighlighted = NO;
        button.adjustsImageWhenHighlighted = NO;
        button;
    });
    [self addSubview:hiddenBtn];
    self.closeBtn = hiddenBtn;
    [hiddenBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(24, 24));
        make.top.equalTo(@12);
        make.trailing.equalTo(@-12);
    }];
    
    [self.callBtn addTarget:self action:@selector(onCallAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.closeBtn addTarget:self action:@selector(onCloseAction) forControlEvents:UIControlEventTouchUpInside];
    [self.nextBtn addTarget:self action:@selector(onNextAction:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)setTtotheUser:(TTotheCallOffersData *)ttotheUser {
    _ttotheUser = ttotheUser;
    
    

}

- (void)onCallAction:(UIButton *)ttothe {
    if (self.ttotheActionBlock) self.ttotheActionBlock(@"CALL");

}

- (void)onNextAction:(UIButton *)ttothe {
    if (self.ttotheActionBlock) self.ttotheActionBlock(@"NEXT");

}

- (void)onCloseAction {
    if (self.ttotheActionBlock) self.ttotheActionBlock(@"CLOSE");

}

@end
